﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace LightControls
{
    [TemplateVisualStateAttribute(Name = "Valid", GroupName = "ValidationStates")]
    [TemplateVisualStateAttribute(Name = "Focused", GroupName = "FocusStates")]
    [TemplateVisualStateAttribute(Name = "InvalidFocused", GroupName = "ValidationStates")]
    [TemplateVisualStateAttribute(Name = "MouseOver", GroupName = "CommonStates")]
    [TemplateVisualStateAttribute(Name = "Pressed", GroupName = "CommonStates")]
    [TemplateVisualStateAttribute(Name = "Disabled", GroupName = "CommonStates")]
    [TemplateVisualStateAttribute(Name = "Unfocused", GroupName = "FocusStates")]
    [TemplateVisualStateAttribute(Name = "Normal", GroupName = "CommonStates")]
    [TemplateVisualStateAttribute(Name = "Checked", GroupName = "CheckStates")]
    [TemplateVisualStateAttribute(Name = "Unchecked", GroupName = "CheckStates")]
    [TemplateVisualStateAttribute(Name = "InvalidUnfocused", GroupName = "ValidationStates")]
    public class LcPushRadioButton: RadioButton
    {

        private Border mainBorder;

        public LcPushRadioButton()
        {
            this.DefaultStyleKey = typeof(LcPushRadioButton);
            this.SetValue(GradientBrushProperty, new SolidColorBrush(Color.FromArgb(255, 68, 141, 202)));
            this.SetValue(FocusBrushProperty, new SolidColorBrush(Color.FromArgb(255, 109, 189, 209)));
            this.SetValue(BorderCornerRadiusProperty, new CornerRadius(3));
            Double d = new Double();
            d = 2;
            this.SetValue(FocusRadiusProperty, d);
            this.SetValue(IsRoundedProperty, true);
        }

        private void changeVisualState(string stateName, bool trans)
        {
            VisualStateManager.GoToState(this, stateName, trans);
        }

        #region Properties
        public static readonly DependencyProperty GradientBrushProperty = DependencyProperty.Register("GradientBrush", typeof(Brush), typeof(LcPushRadioButton), null);
        public static readonly DependencyProperty FocusBrushProperty = DependencyProperty.Register("FocusBrush", typeof(Brush), typeof(LcPushRadioButton), null);
        public static readonly DependencyProperty IsRoundedProperty = DependencyProperty.Register("IsRounded", typeof(bool), typeof(LcPushRadioButton), null);
        public static readonly DependencyProperty BorderCornerRadiusProperty = DependencyProperty.Register("BorderCornerRadius", typeof(CornerRadius), typeof(LcPushRadioButton), null);
        public static readonly DependencyProperty FocusRadiusProperty = DependencyProperty.Register("FocusRadius", typeof(double), typeof(LcPushRadioButton), null);


        public Brush GradientBrush
        {
            set
            {
                SetValue(GradientBrushProperty, value);
            }

            get
            {
                return (Brush)GetValue(GradientBrushProperty);
            }
        }

        public Brush FocusBrush
        {
            set
            {
                SetValue(FocusBrushProperty, value);
            }

            get
            {
                return (Brush)GetValue(FocusBrushProperty);
            }
        }

        
        public bool IsRounded
        {
            set
            {
                SetValue(IsRoundedProperty, value);
                if (value == true)
                {
                    SetValue(BorderCornerRadiusProperty, new CornerRadius(3));
                    SetValue(FocusRadiusProperty, (Double)2);
                }
                else
                {
                    SetValue(BorderCornerRadiusProperty, new CornerRadius(0));
                    SetValue(FocusRadiusProperty, (Double)0);
                }
            }

            get
            {
                return (bool)GetValue(IsRoundedProperty);
            }
        }

        #endregion

        #region Events

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.mainBorder = base.GetTemplateChild("Background") as Border;
        }
        #endregion


        



        

       
    }

    
}
